#配置日志路径
if [ -z "$ORA_SLA_IP" ];then
    ethname=`/usr/sbin/ip r|grep default|awk '{print $5}'`
    ORA_PRI_IP=$(/usr/sbin/ip a|grep $ethname|grep inet|awk '{print $2}'|awk -F'/' '{print $1}')
fi
typeset SCRIPT_NAME="oracle_slave_stop_${ORA_SLA_IP}"
typeset LOG_PATH='/tmp/dr_log'
[ ! -d "${LOG_PATH}" ] && mkdir -p ${LOG_PATH}
typeset LOG_FILE="${LOG_PATH}/${SCRIPT_NAME}.log"
function log_format()
{
    echo "[`date +"%F %H:%M:%S"`] [$*]" | tee -a ${LOG_FILE}
}

if [ ! -f "${LOG_FILE}" ];then
    touch ${LOG_FILE}
    if [ $? -ne 0 ];then
        log_format "ERROR" "failed to create log file" && log_format "ERROR" "script_execute_error!" && exit 1
    else
        log_format "INFO" "success to create log file"
    fi
fi

# log_format "begin to build oracle slave................................."

#设置oracle环境变量
source ~/.bash_profile

#检查check次数
[ ! ${check_times} ] && typeset check_times='3'
expr 1 + ${check_times} &>/dev/null
if [ $? -ne 0 ];then
    log_format "ERROR" 'Argument needs to be integer' && log_format "ERROR" "script_execute_error!" && exit 1
fi

sqlplus / as sysdba <<eof  > /tmp/slave_log.txt
set linesize 300;
set pagesize 300;
column NAME format a30
column VALUE format a20
column UNIT format a40
column TIME_COMPUTED format a30
column DATUM_TIME format a30
select * from V\$DATAGUARD_STATS;  
eof

cat /tmp/slave_log.txt |grep -A 5 'UNIT'
if [ $? -ne 0 ];then
    log_format "ERROR" "script_execute_error!" && exit 1
else
    log_format "INFO" "script_execute_success!"
fi